package com.phpxiu.app.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.phpxiu.app.kkylive.R;
import com.phpxiu.app.model.list.DrawContent;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * Created by WuJinZhou on 2016/6/5.
 */
public class DrawRecordListAdapter extends BaseAdapter<DrawContent> {
    private String stateSuccess,stateFail,stateWorking,unit;
    private SimpleDateFormat df=new SimpleDateFormat("yyyy/MM/dd");
    public DrawRecordListAdapter(Context context, List<DrawContent> data) {
        super(context, data);
        stateSuccess=context.getString(R.string.ui_draw_success);
        stateFail=context.getString(R.string.ui_draw_failed);
        stateWorking=context.getString(R.string.ui_draw_doing);
        unit=context.getString(R.string.rmb_unit);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        DrawContent content=data.get(position);
        if(convertView==null){
            convertView=mInflater.inflate(R.layout.user_income_draw_record_list_item_view,null);
        }
        TextView money=(TextView)convertView.findViewById(R.id.money);
        money.setText(content.getMoney() + unit);
        TextView time=(TextView)convertView.findViewById(R.id.time);
        String timeStr=df.format(new Date(content.getCreate_time()));
        time.setText(timeStr);
        TextView state=(TextView)convertView.findViewById(R.id.result_state);
        if("1".equals(state)){
            state.setText(stateSuccess);
        }else{
            state.setText(stateFail);
        }
        convertView.findViewById(R.id.item_divider).setVisibility(View.VISIBLE);
        if(data.size()>0&&position==data.size()-1){
            convertView.findViewById(R.id.item_divider).setVisibility(View.INVISIBLE);
        }
        return convertView;
    }
}
